package cn.tutu.blockchain.mining.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.tutu.blockchain.common.Page;
import cn.tutu.blockchain.mining.dao.MiningRecordsDao;
import cn.tutu.blockchain.mining.entity.MiningRecords;
import cn.tutu.blockchain.mining.service.MiningRecordsService;

/**
 * 
 * <p>
 * Title: MiningRecordsServiceImpl
 * </p>
 * <p>
 * Description:挖矿记录业务层
 * </p>
 * 
 * @author 眭善峰
 * @date 2018年4月24日
 *
 */
@Service
@Transactional
public class MiningRecordsServiceImpl implements MiningRecordsService {

	@Autowired
	private MiningRecordsDao miningRecordsDao;

	@Override
	public void create(MiningRecords miningRecords) {
		// TODO 根据矿机ID获取用户ID
		miningRecordsDao.insert(miningRecords);
	}

	@Override
	public PageInfo<MiningRecords> getByEthId(String ethId, Page page) {
		PageHelper.startPage(page.getPageNum(), page.getPageSize());
		List<MiningRecords> list = miningRecordsDao.findByEthId(ethId);
		PageInfo<MiningRecords> pageInfo = new PageInfo<MiningRecords>(list);
		return pageInfo;
	}

	@Override
	public void removeByTimeout() {
		miningRecordsDao.insertBak();
		miningRecordsDao.deleteByTimeout();
	}

}
